// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()

const db = cloud.database();
const col = db.collection('test02');
const _ = db.command;

// 云函数入口函数
exports.main = async (event, context) => {
    const wxContext = cloud.getWXContext()

    db.collection('test02').where({
    }).get({ // get 方法会触发网络请求，往数据库取数据
        success: (res) => {
            //保存数据
            this.setData({
                wordList: res.data[0].words
            })

        }
    })

    return {
        wordList,
        event,
        openid: wxContext.OPENID,
        appid: wxContext.APPID,
        unionid: wxContext.UNIONID,
    }
}